<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('阀门设备数据列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>阀门ID：</label>
                                <input type="text" name="valveId"/>
                            </li>
                            <li>
                                <label>采集器ID：</label>
                                <input type="text" name="concentratorId"/>
                            </li>
                            <li>
                                <label>阀门型号：</label>
                                <select id="valveType" name="typeId">
                                    <option value="0">所有</option>
                                    <option th:each="valve : ${valveList}" th:text="${valve['typeName']}" th:value="${valve['typeId']}" th:field="*{type.typeId}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>安装时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginInstallTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endInstallTime]"/>
                            </li>
                            <li>
                                <label>安装标识：</label>
                                <select name="status" th:with="type=${@dict.getType('equipment_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="module:valve:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="module:valve:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="module:valve:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.importExcel()" shiro:hasPermission="module:valve:import">
                    <i class="fa fa-download"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="module:valve:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <br/>
                <a class="btn btn-primary multiple disabled" onclick="register()" shiro:hasPermission="module:valve:register">
                    <i class="fa fa-download"></i> 阀门登记
                </a>
                <a class="btn btn-warning multiple disabled" onclick="cancel()" shiro:hasPermission="module:valve:cancel">
                    <i class="fa fa-download"></i> 阀门注销
                </a>
                <a class="btn btn-warning multiple disabled" onclick="aperture()" shiro:hasPermission="module:valve:aperture">
                    <i class="fa fa-download"></i> 设置阀门开度
                </a>
                <a class="btn btn-warning multiple disabled" onclick="limit()" shiro:hasPermission="module:valve:limit">
                    <i class="fa fa-download"></i> 限制阀门开启
                </a>
                <a class="btn btn-warning multiple disabled" onclick="check()" shiro:hasPermission="module:valve:check">
                    <i class="fa fa-download"></i> 读取阀门数据
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('module:valve:edit')}]];
        var removeFlag = [[${@permission.hasPermi('module:valve:remove')}]];
        var prefix = ctx + "module/valve/data";
        var datas = [[${@dict.getType('equipment_status')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                queryParams: queryParams,
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "阀门设备数据",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'valveId',
                    title: '阀门ID',
                    formatter: function(value, row, index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.valveId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'status',
                    title: '设备状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'valveType.typeName',
                    title: '阀门型号'
                },
                {
                    field: 'concentratorId',
                    title: '采集器'
                },
                {
                    field: 'installTime',
                    title: '安装时间'
                },
                {
                    field: 'installAddress',
                    title: '安装地址'
                },
                {
                    field: 'installUser',
                    title: '安装人'
                },
                {
                    field: 'factory.factoryName',
                    title: '厂商名称'
                },
                {
                    field: 'factory.factoryCode',
                    title: '厂商代码'
                },
                {
                    field: 'aperture',
                    title: '阀门开度'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.valveId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.valveId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 阀门数据 */
        function detail(valveId) {
            var url = ctx + 'module/valve/record/' + valveId;
            $.modal.openTab("阀门数据", url);
        }

        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.typeId = $("#valveType").val();
            return search;
        }

        function add(){
            var valveType = $("#valveType option:selected").val();
            $.operate.add(valveType);
        }

        function register(){
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要登记选中的阀门吗？", function() {
                $.operate.post(prefix + "/register", { "valveIds": rows.join() });
            })
        }

        function cancel(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status=="0"){
                    $.modal.alertWarning("未登记的阀门信息不允许注销");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            $.modal.confirm("确认要注销选中的阀门吗？", function() {
                $.operate.post(prefix + "/cancel", { "valveIds": rows.join() });
            })
        }

        function aperture(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status!="1"){
                    $.modal.alertWarning("未登记的阀门不允许设置阀门开度");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            var url = prefix + '/aperture/' + rows.join();
            $.modal.open("设置阀门开度", url, '800', '300');
        }

        function check(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status!="1"){
                    $.modal.alertWarning("未登记的阀门不能读取阀门数据");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            $.operate.post(prefix + "/check", { "valveIds": rows.join() });
        }

        function limit(){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            for(var i=0;i<rows.length;i++){
                var row = rows[i];
                var status = row["status"];
                if(status!="1"){
                    $.modal.alertWarning("未登记的阀门不能限制阀门开启");
                    return;
                }
            }
            var rows = $.table.selectFirstColumns();
            $.operate.post(prefix + "/limit", { "valveIds": rows.join() });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果阀门信息已经存在，更新这条数据。"> 是否更新已经存在的阀门信息
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>